using System;
using System.Threading.Tasks;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services.Openmerch.Bill;
using JlPay.Sdk.Models.Openmerch.Bill;

namespace JlPay.Sdk.Examples.Openmerch.Bill.SettleBillQuery
{
    /// <summary>
    /// 结算账单查询使用示例
    /// @author liaochangyi
    /// @since 2025-01-25
    /// </summary>
    public class SettleBillQueryDemo
    {
        /// <summary>
        /// 主程序入口
        /// </summary>
        /// <param name="args">命令行参数</param>
        /// <returns>任务</returns>
        public static async Task Main(string[] args)
        {
            Console.WriteLine("==========================================");
            Console.WriteLine("===== 结算账单查询示例 开始 =====");
            Console.WriteLine("==========================================");
            Console.WriteLine();

            await SettleBillQueryDemoAsync();

            Console.WriteLine("==========================================");
            Console.WriteLine("===== 结算账单查询示例执行完毕 =====");
            Console.WriteLine("==========================================");
        }

        /// <summary>
        /// 创建配置对象
        /// </summary>
        /// <returns>配置对象</returns>
        private static Config CreateConfig()
        {
            return DemoConfig.CreateConfig();
        }

        /// <summary>
        /// 构建结算账单查询请求
        /// </summary>
        /// <returns>请求对象</returns>
        private static SettleBillQueryRequest BuildSettleBillQueryRequest()
        {
            var request = new SettleBillQueryRequest
            {
                MerchNo = "849584358120018",
                StartBusiDate = "2024-07-01",
                EndBusiDate = "2024-07-02",
                StartSettleDate = "2024-07-01",
                EndSettleDate = "2024-07-02",
                PayStatus = "1"
            };

            return request;
        }

        /// <summary>
        /// 结算账单查询示例
        /// </summary>
        public static async Task SettleBillQueryDemoAsync()
        {
            Console.WriteLine("开始执行结算账单查询示例");
            
            try
            {
                // 创建配置对象和账单服务
                var config = CreateConfig();
                var billService = new BillService(config);
                
                // 创建结算账单查询请求
                var request = BuildSettleBillQueryRequest();
                
                // 发送请求
                var response = await billService.SettleBillQueryAsync(request);
                
                // 处理响应结果
                response.HandleResponse("结算账单查询", config);
            }
            catch (Exception ex)
            {
                var config = CreateConfig();
                var response = new SettleBillQueryResponse();
                response.HandleResponseWithException("结算账单查询", config, ex);
            }
            
            Console.WriteLine("结算账单查询示例执行完毕");
        }
    }
} 